﻿namespace EFS.RC.Survey.Controls.HyperlinkButtons
{
	public class Open : EFS.RC.Survey.Controls.HyperlinkButtons.Base
	{
		/// Property AuthorisationOverview: Get
		public virtual EFS.RC.CC.CH.Entities.Surveys.Sessions.SessionInfo SessionInfo
		{
			get
			{
				// get parent
				System.Windows.Controls.DataGridCell dataGridCell = this.Parent as System.Windows.Controls.DataGridCell;
				if (null == dataGridCell)
				{
					return null;
				}

				// get datacontext
				EFS.RC.CC.CH.Entities.Surveys.Sessions.SessionInfo sessionInfo = dataGridCell.DataContext as EFS.RC.CC.CH.Entities.Surveys.Sessions.SessionInfo;

				// ok
				return sessionInfo;
			}
		}

		/// UpdateUI
		protected override void UpdateUI()
		{
			// call base
			base.UpdateUI();

			// get session info
			EFS.RC.CC.CH.Entities.Surveys.Sessions.SessionInfo sessionInfo = SessionInfo;

			// enabled
			this.IsEnabled = null != sessionInfo && !sessionInfo.ReadOnly;
		}
	}

}